package com.bdth.weget.business.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.bdth.weget.business.entity.Warnning;
import com.bdth.weget.business.mapper.WarnningMapper;
import com.bdth.weget.business.service.WarnningService;
import com.bdth.weget.util.DateUtil;
import com.bdth.weget.vo.JT0200;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/7/16.
 */
@Service
public class WarnningServiceImpl extends ServiceImpl<WarnningMapper, Warnning> implements WarnningService {
    @Autowired
    public WarnningMapper warnningMapper;

    @Override
    public boolean insert(JT0200 bean) {
        Warnning w = new Warnning();
        w.setCarid(bean.getCarid());
        w.setSimno(bean.getSimno());
        w.setOp(0);
        w.setUpdatetime(DateUtil.str2date(bean.getTime(),"yyyy-MM-dd HH:mm:ss"));
        boolean falg = insertList(w,bean.getAlarmFlag().toList());
        return falg;
    }

    @Override
    public boolean insertList(Warnning bean, List<String> list) {
        List<Warnning>  value = new ArrayList<>();
        if(bean!=null&&list!=null&& list.size()>0){
            for (String msg:list) {
                bean.setWarnmsg(msg);
                bean.setOp(0);
                value.add(bean);
            }
        }else{
            return false;
        }

        warnningMapper.insertForeach(value);
        return true;
    }

    @Override
    public List<Warnning> listWarnningByCarid(Integer carid) {
        return null;
    }

    @Override
    public List<Warnning> listWarnningLastTopN(int n) {
        return null;
    }
}
